package noticedto

import (
	"github.com/gogf/gf/v2/frame/g"
	"time"
	"xr-game-server/entity"
	"xr-game-server/gameevent"
)

type PushNoticeReq struct {
	g.Meta `path:"/pushNotice" method:"post" summary:"推送公告 命令字 15" tags:"公告"`
}

type PushNotice struct {
	TypeId        uint8 `json:"typeId" dc:"广播类型"`
	Param         []any `json:"param" dc:"参数"`
	CountDownTime int64 `json:"endTime" dc:"持续时间(秒),循环间隔时间拿配置表,0表示只播放一次"`
}

func NewPushAppNotice(event *gameevent.NoticeEventData) *PushNotice {
	return &PushNotice{
		TypeId: event.TypeId,
		Param:  event.Param,
	}
}

func NewPushDtoByEntity(notice *entity.Notice) *PushNotice {
	ret := &PushNotice{
		TypeId: notice.TypeId,
	}
	now := time.Now()
	if notice.CanSend() {
		ret.CountDownTime = notice.EndTime.Sub(now).Milliseconds()
	}
	ret.Param = notice.GetParam()
	return ret
}

func NewOncePushDto(req *AddOnceNoticeReq) *PushNotice {
	ret := &PushNotice{
		TypeId: req.TypeId,
	}
	ret.Param = req.GetParam()
	return ret
}
